//logs.js
var postData = require('../../data/post-data.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    clickId: -1,
    clickIds: -1,
    clickIdse: -1,
    the_miji: '面积',
    the_housetype: "户型",
    the_price: "价格",
    lastX: 0, //滑动开始x轴位置
    lastY: 0 ,//滑动开始y轴位置
    scrollTop: 0,
    icon_imagef:"https://img.xtuan.com/xcximgtest/images/materal/down.png",
    icon_imagec: "https://img.xtuan.com/xcximgtest/images/materal/down.png",
    icon_imaget: "https://img.xtuan.com/xcximgtest/images/materal/down.png"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    this.setData({
      showsearch: true,
      postlist: postData.postlist,
      hosudaxia: postData.thehosealear,
      housstyle: postData.housstyle,
      houseprice: postData.houseprice,
    })
  },
  stopmove: function(e) {},
  preventTouchMove: function(e) {},
  stopTouchMove: function(e) {},
  noTouchMove: function(e) {},
  //头部导航点击事件
  chos_alear: function() {
    var that = this
    var martop = 0;
    var positions = 'fixed'
    var the_color ="green"
    var other ="rgb(153,153,153)"
    var icondown ="https://img.xtuan.com/xcximgtest/images/materal/up_green.png"
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    this.setData({
      showacerage: true,
      showhouse: false,
      showsearch: false,
      showprice: false,
      showMask: true,
      martop: martop,
      status: positions,
      the_color: the_color,
      the_hcolor: other,
      the_pcolor: other,
      icon_imagef:icondown,
      icon_imagec: sames_image,
      icon_imaget: sames_image,
    })
  },
  chose_house: function() {
    var that = this
    var martop = 0;
    var positions = 'fixed'
    var the_color = "green"
    var other = "rgb(153,153,153)"
    var icondown = "https://img.xtuan.com/xcximgtest/images/materal/up_green.png"
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    this.setData({
      showhouse: true,
      showacerage: false,
      showsearch: false,
      showprice: false,
      showMask: true,
      martop: martop,
      status: positions,
      the_hcolor: the_color,
      the_color: other,
      the_pcolor: other,
      icon_imagef: sames_image,
      icon_imagec: icondown,
      icon_imaget: sames_image,
    })
  },
  chose_price: function() {
    var that = this
    var martop = 0;
    var positions = 'fixed'
    var the_color = "green"
    var other = "rgb(153,153,153)"
    var icondown = "https://img.xtuan.com/xcximgtest/images/materal/up_green.png"
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    this.setData({
      showprice: true,
      showhouse: false,
      showacerage: false,
      showsearch: false,
      showMask: true,
      martop: martop,
      status: positions,
      the_pcolor: the_color,
      the_hcolor: other,
      the_color: other,
      icon_imagef: sames_image,
      icon_imagec: sames_image,
      icon_imaget: icondown,
    })
  },
  // 面积点击改变按钮颜色
  choose_acerage: function(e) {
    var that = this;
    var martop = 100;
    var positions = 'absolute';
    var length = that.data.clickId;
    var index = parseInt(e.currentTarget.id);
    var value = that.data.hosudaxia[index];
    var other = "rgb(153,153,153)";
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    if (this.data.clickId == e.currentTarget.id) {
      this.setData({
        clickId: +1,
        the_miji: value
      })
      return;
    }
    that.setData({
      clickId: e.currentTarget.id,
      showacerage: false,
      showMask: false,
      showprice: false,
      showsearch: true,
      martop: martop,
      status: positions,
      the_miji: value,
      icon_imagef: sames_image,
      icon_imagec: sames_image,
      icon_imaget: sames_image,
      the_color: other,
      the_hcolor: other,
      the_pcolor: other,
    })


    console.log(value)
    console.log(that);
  },
  //户型选择
  choose_house: function(e) {
    if (this.data.clickIds == e.currentTarget.id) {
      this.setData({
        clickIds: +1
      })
      return;
    }
    var martop = 100;
    var positions = 'absolute';
    var length = this.data.in;
    var index = parseInt(e.currentTarget.id);
    var value = this.data.housstyle[index];
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    var other = "rgb(153,153,153)"
    this.setData({
      clickIds: e.currentTarget.id,
      showhouse: false,
      showMask: false,
      showprice: false,
      showsearch: true,
      martop: martop,
      status: positions,
      the_housetype: value,
      icon_imagef: sames_image,
      icon_imagec: sames_image,
      icon_imaget: sames_image,
      the_color: other,
      the_hcolor: other,
      the_pcolor: other,
    })
    var index = e.currentTarget.id;
    console.log(value);

  },
  //价格选择
  choose_price: function(e) {
    if (this.data.clickIdse == e.currentTarget.id) {
      this.setData({
        clickIdse: +1
      })
      return;
    }
    var martop = 100;
    var positions = 'absolute';
    var length = this.data.clickIdse;
    var index = parseInt(e.currentTarget.id);
    var value = this.data.houseprice[index];
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    var other = "rgb(153,153,153)"
    this.setData({
      clickIdse: e.currentTarget.id,
      showprice: false,
      showhouse: false,
      showMask: false,
      showsearch: true,
      martop: martop,
      status: positions,
      the_price: value,
      icon_imagef: sames_image,
      icon_imagec: sames_image,
      icon_imaget: sames_image,
      the_color: other,
      the_hcolor: other,
      the_pcolor: other,
    })
    var index = e.currentTarget.id;
    console.log(index);
  },

  hidden:function(e){
    var that = this
    var sames_image = "https://img.xtuan.com/xcximgtest/images/materal/down.png"
    var other = "rgb(153,153,153)"
    var martop = 100;
    var positions = 'absolute';
    that.setData({
      showprice: false,
      showhouse: false,
      showMask: false,
      showsearch: true,
      martop: martop,
      status: positions,
      icon_imagef: sames_image,
      icon_imagec: sames_image,
      icon_imaget: sames_image,
      the_color: other,
      the_hcolor: other,
      the_pcolor: other,
    })
  },
  //到详情页面
  binddetail: function (e) {
    var arcleId = e.currentTarget.dataset.arcleid;
    wx.navigateTo({
      url: "../detail/index_detail?id=" + arcleId
    })
    console.log(arcleId);
  },
 
  //监听页面滚动事件
  onPageScroll: function (ev) {
    var _this = this;
    var martop = 0;
    var positions = 'fixed'
    var martops = 100;
    var positionse = 'absolute';
    //当滚动的top值最大或最小时，为什么要做这一步是因为在手机实测小程序的时候会发生滚动条回弹，所以为了处理回弹，设置默认最大最小值
    if (ev.scrollTop <= 50) {
      ev.scrollTop = 0;
      this.setData({
          martop: martops,
          status: positionse
        })
    } else if (ev.scrollTop > 50) {
      ev.scrollTop = wx.getSystemInfoSync().windowHeight;
      this.setData({
          martop: martop,
          status: positions
        })      
    }
    //判断浏览器滚动条上下滚动
    if (ev.scrollTop > this.data.scrollTop || ev.scrollTop == wx.getSystemInfoSync().windowHeight) {
      //向下滚动
    } else {
      //向上滚动
    }
    //给scrollTop重新赋值
    setTimeout(function () {
      _this.setData({
        scrollTop: ev.scrollTop
      })
    }, 0)
  },
  //上拉加载
  onReachBottom: function () {
    var that = this
   
    wx.showLoading({ //显示toast
      title: '没有更多了',
    });
    setTimeout(function(){
      wx.hideLoading();
    },2000)
    
  },
  //下拉刷新
  onPullDownRefresh: function () {
    var that = this
 
   
  },
})